package com.vpen.client.stomp;

import cn.hutool.core.util.RandomUtil;
import com.vpen.client.matter.MatterClient;
import com.vpen.common.Matter;
import com.vpen.common.Picture;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

/**
 * 描述
 *
 * @author 韦鹏
 * @date 2022/11/28 22:31
 */
@Slf4j
@RestController
@RequestMapping("stomp")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class StompClientController {

    private final StompWebsocketClient stompWebsocketClient;

    /**
     * 连接
     */
    @GetMapping("connect")
    public void connect() throws ExecutionException, InterruptedException {
        stompWebsocketClient.connect();
    }

    /**
     * 断开连接
     */
    @GetMapping("disconnect")
    public void disconnect() {
        stompWebsocketClient.disconnect();
    }


    /**
     * 发送到指定的url
     */
    @GetMapping("send/{channel}")
    public void sendMsg(@PathVariable("channel") String channel,
                        @RequestParam("msg") String msg) {
        stompWebsocketClient.send("/app/" + channel, msg);
    }

    /**
     * 订阅
     */
    @GetMapping("subscribe")
    public void subscribe(@RequestParam("topic") String topic) {
        stompWebsocketClient.subscribe(topic);
    }
}
